<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/8/1
 * Time: 1:02 PM
 */
namespace app\common\services\theme\datas;

use app\common\models\Category;

class CategoryList
{
    public function getData($ids,$isEdit=false){
        if(!$ids){
            return [];
        }
        $query = Category::site()->select();
        $query->whereIn('id',$ids);
        $list = $query
            ->with(['parent' => function($query) {
                return $query->select('id','pid','name');
            }])
            ->orderBy('id', 'desc')
            ->take();
        if(!$list){
            return [];
        }
        $list->map(function ($v){
            $v->type_desc = Category::$typeMap[$v->type];
            $v->pname = '一级分类';
            if($v['parent'] && $v['parent']['name']){
                $v->pname = $v['parent']['name'];

            }
        });
        return $list;
    }
}
